{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1*1=1\t\n",
      "1*2=2\t2*2=4\t\n",
      "1*3=3\t2*3=6\t3*3=9\t\n",
      "1*4=4\t2*4=8\t3*4=12\t4*4=16\t\n",
      "1*5=5\t2*5=10\t3*5=15\t4*5=20\t5*5=25\t\n",
      "1*6=6\t2*6=12\t3*6=18\t4*6=24\t5*6=30\t6*6=36\t\n",
      "1*7=7\t2*7=14\t3*7=21\t4*7=28\t5*7=35\t6*7=42\t7*7=49\t\n",
      "1*8=8\t2*8=16\t3*8=24\t4*8=32\t5*8=40\t6*8=48\t7*8=56\t8*8=64\t\n",
      "1*9=9\t2*9=18\t3*9=27\t4*9=36\t5*9=45\t6*9=54\t7*9=63\t8*9=72\t9*9=81\t\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "\n",
    "\n",
    "# 输出乘法口诀表\n",
    "def print_multiplication_table():\n",
    "    for i in range(1, 10):\n",
    "        for j in range(1, i + 1):\n",
    "            print(f\"{j}*{i}={i * j}\", end='\\t')\n",
    "        print()\n",
    "\n",
    "\n",
    "# 分解质因数\n",
    "def prime_factors(n):\n",
    "    factors = []\n",
    "    while n % 2 == 0:\n",
    "        factors.append(2)\n",
    "        n = n / 2\n",
    "    for i in range(3, int(math.sqrt(n)) + 1, 2):\n",
    "        while n % i == 0:\n",
    "            factors.append(i)\n",
    "            n = n / i\n",
    "    if n > 2:\n",
    "        factors.append(int(n))\n",
    "    return factors\n",
    "\n",
    "\n",
    "# 处理不多于6位正整数输入及相关操作\n",
    "def handle_six_digit_number():\n",
    "    while True:\n",
    "        num_str = input(\"请输入一个不多于6位的正整数：\")\n",
    "        if num_str.isdigit() and len(num_str) <= 6:\n",
    "            break\n",
    "        print(\"输入不合法，请输入不多于6位的正整数！\")\n",
    "\n",
    "    print(f\"该数字是{len(num_str)}位数。\")\n",
    "    print(num_str[::-1])\n",
    "\n",
    "\n",
    "# 计算特定格式数字相加的和\n",
    "def sum_series():\n",
    "    n = int(input(\"请输入相加的数字个数：\"))\n",
    "    a = int(input(\"请输入数字a：\"))\n",
    "    sum_value = 0\n",
    "    temp = 0\n",
    "    for i in range(1, n + 1):\n",
    "        temp = temp * 10 + a\n",
    "        sum_value += temp\n",
    "    print(\"结果为:\", sum_value)\n",
    "\n",
    "\n",
    "# 计算分数序列前N项和\n",
    "def sum_fraction_sequence():\n",
    "    n = int(input(\"请输入项数N：\"))\n",
    "    sum_value = 0\n",
    "    a, b = 2, 1\n",
    "    for _ in range(1, n + 1):\n",
    "        sum_value += a / b\n",
    "        temp = a\n",
    "        a = a + b\n",
    "        b = temp\n",
    "    print(\"前{}项之和为：{}\".format(n, round(sum_value, 3)))\n",
    "\n",
    "\n",
    "# 查找满足条件的整数\n",
    "def find_specific_integer():\n",
    "    for integer in range(1, 100000):\n",
    "        numItem_1 = math.sqrt(integer + 100)\n",
    "        numItem_2 = math.sqrt(integer + 268)\n",
    "        if numItem_1 == int(numItem_1) and numItem_2 == int(numItem_2):\n",
    "            print(integer)\n",
    "\n",
    "\n",
    "# 计算兔子对数\n",
    "def calculate_rabbit_count():\n",
    "    month = int(input(\"请输入月数：\"))\n",
    "    a, b = 1, 1\n",
    "    for _ in range(1, month + 1):\n",
    "        print(f\"第{_}个月的兔子对数: {a}\")\n",
    "        a, b = b, a + b\n",
    "\n",
    "\n",
    "# 主函数，根据用户输入调用不同功能\n",
    "def main():\n",
    "    try:\n",
    "        user_input = int(input(\"请输入一个1到10之间的整数: \"))\n",
    "        if 1 <= user_input <= 10:\n",
    "            if user_input == 1:\n",
    "                print_multiplication_table()\n",
    "            elif user_input == 2:\n",
    "                num = int(input(\"请输入一个正整数：\"))\n",
    "                result = prime_factors(num)\n",
    "                print(f\"{num}=\", end='')\n",
    "                print('*'.join(map(str, result)))\n",
    "            elif user_input == 3:\n",
    "                handle_six_digit_number()\n",
    "            elif user_input == 4:\n",
    "                sum_series()\n",
    "            elif user_input == 5:\n",
    "                sum_fraction_sequence()\n",
    "            elif user_input == 6:\n",
    "                find_specific_integer()\n",
    "            elif user_input == 7:\n",
    "                calculate_rabbit_count()\n",
    "            elif user_input == 8:\n",
    "                # 假设这里后续实现对应功能函数sort_numbers\n",
    "                sort_numbers()\n",
    "            elif user_input == 9:\n",
    "                sorted_array = [0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60]\n",
    "                new_num = int(input(\"请输入要插入的新数字: \"))\n",
    "                # 假设这里后续实现对应功能函数insert_sorted_array\n",
    "                sorted_array = insert_sorted_array(sorted_array, new_num)\n",
    "                print(\"插入新数字后的数组:\", sorted_array)\n",
    "            elif user_input == 10:\n",
    "                # 假设这里后续实现对应功能函数josephus_problem\n",
    "                n = int(input(\"请输入总人数: \"))\n",
    "                last_person = josephus_problem(n)\n",
    "                print(f\"最后留下的那个人是原来第 {last_person} 号。\")\n",
    "        else:\n",
    "            print(\"输入的数字不在1到10之间，请重新输入。\")\n",
    "    except ValueError:\n",
    "        print(\"无效输入，请输入一个1到10之间的整数！\")\n",
    "\n",
    "\n",
    "if __name__ == \"__main__\":\n",
    "    main()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
